<Project>
  <PropertyGroup>
    <DotnetProducts>C:\work\main</DotnetProducts>
    <DotnetHive>Main</DotnetHive>
    <DotnetProductsOut>$(DotnetProducts)\Bin.$(DotnetHive)</DotnetProductsOut>
    <CopyFromTargetFramework>net461</CopyFromTargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <DotnetProductsNuPkg Include="$(DotnetProducts)\Packages\$(PackageId).2*\*.nupkg"/>
    <DotnetProductsAssembly Include="$(DotnetProducts)\Packages\$(PackageId).2*\lib\$(CopyFromTargetFramework)\$(AssemblyName).dll"/>
    <DotnetProductsOutput Include="$(OutputPath)\$(AssemblyName).*" />
  </ItemGroup>
  <Target Name="CopyToRd" AfterTargets="AfterBuild"  Condition="'$(IsPackable)' != 'false' AND '$(PackageId)' != '' AND '$(TargetFramework)' == '$(CopyFromTargetFramework)'">
    <Error Text="$(PackageId) package is not found in $(DotnetProducts)\Packages"
      Condition="'@(DotnetProductsNuPkg)' == ''" />
    <Error Text="$(AssemblyName).dll is not found in $(DotnetProducts)\Packages\$(PackageId)\lib\$(CopyFromTargetFramework)" 
      Condition="'@(DotnetProductsAssembly)' == ''" />
    <Error Text="Files by mask $(AssemblyName).* are not found in $(OutputPath)"
      Condition="'@(DotnetProductsOutput)' == ''" />

    <Copy SourceFiles="@(DotnetProductsOutput)" DestinationFolder="$(DotnetProductsOut)" ContinueOnError="false" />
    <CombinePath BasePath="@(DotnetProductsNuPkg->'%(RootDir)%(Directory)')" Paths="lib\$(CopyFromTargetFramework)">
      <Output TaskParameter="CombinedPaths" ItemName="DotnetProductsPackageLibDir" />
    </CombinePath>
    <Copy SourceFiles="@(DotnetProductsOutput)" DestinationFolder="@(DotnetProductsPackageLibDir)" ContinueOnError="false" />
  </Target>
  <Target Name="CleanRd" AfterTargets="Clean"  Condition="'$(TargetFramework)' == '$(CopyFromTargetFramework)'">
    <Unzip SourceFiles="@(DotnetProductsNuPkg)" DestinationFolder="@(DotnetProductsNuPkg->'%(RootDir)%(Directory)')"/>
    <Copy SourceFiles="@(DotnetProductsAssembly)" DestinationFolder="$(DotnetProductsOut)" ContinueOnError="false" />
  </Target>
</Project>